package Homework6;

import java.util.InputMismatchException;
import java.util.Scanner;

public class Homework6_1 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n1 = 0, n2 = 0;
        boolean validInput = false;

        System.out.println("Please enter two integers:");

        while (!validInput) {
            try {
                String line = scanner.nextLine();
                String[] parts = line.trim().split("\\s+");
                if (parts.length != 2) {
                    throw new InputMismatchException();
                }
                n1 = Integer.parseInt(parts[0]);
                n2 = Integer.parseInt(parts[1]);
                validInput = true;
            } catch (Exception e) {
                System.out.println("InputMismatchException: Please input n1 and n2 again.");
            }
        }

        int sum = n1 + n2;
        System.out.println("sum is " + sum);
    }
}
